Don't assume vcpu_id's are contiguous in alloc_vcpu
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 12 Nov 2009 13:15:40 +0000 (13:15 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 12 Nov 2009 13:15:40 +0000 (13:15 +0000)
When cpu hot-added, this assumption is broken because the hot-added
CPU may be brougt online by dom0 in arbitrary order. This patch avoids
making this assumption while still linking vcpus in ascending order of
identifier.

Signed-off-by: Jiang, Yunhong <yunhong.jiang@intel.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
xen/common/domain.c

index d47b55a93983b58e3d82c6c9dc681c027406f3f3..6d445d61b6d4577af9b89d7529614f75a746a320 100644 (file)
@@ -176,7 +176,14 @@ struct vcpu *alloc_vcpu(
 
     d->vcpu[vcpu_id] = v;
     if ( vcpu_id != 0 )
-        d->vcpu[v->vcpu_id-1]->next_in_list = v;
+    {
+        int prev_id = v->vcpu_id - 1;
+        while ( (prev_id >= 0) && (d->vcpu[prev_id] == NULL) )
+            prev_id--;
+        BUG_ON(prev_id < 0);
+        v->next_in_list = d->vcpu[prev_id]->next_in_list;
+        d->vcpu[prev_id]->next_in_list = v;
+    }
 
     /* Must be called after making new vcpu visible to for_each_vcpu(). */
     vcpu_check_shutdown(v);